/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import Controller.Salle;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Charly
 */
public class SalleDAO extends AbstractDAO<Salle>{
   public SalleDAO(Connection connect) 
    {
        super(connect);
    }

  @Override
  protected boolean insert(Salle obj) {
	throw new UnsupportedOperationException("Not supported yet.");
  }

  @Override
  protected boolean update(Salle obj) {
	throw new UnsupportedOperationException("Not supported yet.");
  }

  @Override
  protected boolean delete(Salle obj) {
	throw new UnsupportedOperationException("Not supported yet.");
  }

  /**
   * Récupère une ville grâce à l'id
   * @param id
   * @return Salle
   */
  @Override
  public Salle findById(int id) {
            Salle salle = new Salle();
	  try {
	   
            ResultSet res = this.connect.createStatement(
            ResultSet.TYPE_SCROLL_INSENSITIVE,
            ResultSet.CONCUR_READ_ONLY).executeQuery("SELECT * FROM salle WHERE idS = " + id);
            
            if(res.first())
            {
                salle.setIdB(res.getInt(1));
                salle.setNomS(res.getString(2));
            }
            
            return salle;
           
        }
        catch (Exception e) {
            e.printStackTrace();
            return null;
        }
	
  }
  
  /**
   * Recup toutes les salles
   * @return Map<Integer,Salle>
   */
  public Map<Integer,Salle> findAll(){	
	  Map<Integer,Salle> mapSalle = new HashMap();
	  try {
			Salle salle = null;
            // 3..creer la requette
            Statement stm=this.connect.createStatement();
            // 4..executer requette
            ResultSet res = stm.executeQuery("SELECT * FROM salle;");
            // 5..parcour des resultat stoque dans la map
            while (res.next()){
                salle = new Salle(res.getInt(1),res.getString(2),res.getInt(3));
                mapSalle.put(res.getInt(1),salle);
            }
            stm.close();
            return mapSalle;
        }
        catch (Exception e) {
            e.printStackTrace();
        }
	  return mapSalle;
  }
}
